package com.liang.jiekou.controller;


import com.alibaba.fastjson.JSON;

import com.digitalpetri.modbus.FunctionCode;
import com.digitalpetri.modbus.codec.Modbus;
import com.digitalpetri.modbus.master.ModbusTcpMaster;
import com.digitalpetri.modbus.master.ModbusTcpMasterConfig;
import com.digitalpetri.modbus.requests.*;
import com.digitalpetri.modbus.responses.*;
import com.liang.jiekou.entity.*;
import com.liang.jiekou.service.HttpClientService;
import com.liang.jiekou.service.PermissionService;
import com.liang.jiekou.service.RUKUService;
import com.liang.jiekou.untils.SimpleMasterExample;
import io.netty.buffer.ByteBuf;
import io.netty.util.ReferenceCountUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.Random;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;


/*
* 入库Controller
* */

@Api(tags = "入库控制器")
@RestController
@Slf4j
@RequestMapping("/rk")
public class RUKUController {

    @Resource
    RUKUService rukuService;


    @ApiOperation("生成并自动审核入库单")
    //调用方法将数据插入MOCTF，MOCTG表
    @PostMapping("/insert")
    public RpcServiceResult<Map<String, Object>> insertData(@RequestBody All all) throws UnknownHostException {
        return rukuService.insertAll(all);
    }

    @ApiOperation("删除入库单")
    @PostMapping("/deleteData")
    public RpcServiceResult<Map<String, Object>> deleteData(
            @RequestParam String CREATOR,
            @RequestParam String TF001,
            @RequestParam String TF002) throws UnknownHostException {
        Result update = rukuService.update(CREATOR, TF001, TF002);
        if (update.getCode() == 1) {
            return rukuService.delete(TF001, TF002);
        }
        return RpcServiceResult.getFailureResult("500","入库失败");
    }

}